package com.cn.zengzeng.spbzengzeng.controller;

import com.alibaba.fastjson.JSONObject;
import com.cn.zengzeng.spbzengzeng.service.AccountService;
import com.cn.zengzeng.spbzengzeng.test.BoJunHttpUtils;
import com.cn.zengzeng.spbzengzeng.utils.LocalThreadPoolTaskExecutor;
import com.cn.zengzeng.spbzengzeng.utils.ThreadPoolExecutorFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * WebSocketController
 * @author zhengkai.blog.csdn.net
 */
@RestController
@RequestMapping("/demo")
@Slf4j
public class DemoController {

    @Resource
    private AccountService accountService ;
    public static final LocalThreadPoolTaskExecutor THREAD_POOL = ThreadPoolExecutorFactory.get();
    @RequestMapping("/push/{toUserId}")
    public ResponseEntity<String> pushToWeb(String message, @PathVariable String toUserId) throws IOException {
        WebSocketServer.sendInfo(message,toUserId);
        return ResponseEntity.ok("MSG SEND SUCCESS");
    }

    @GetMapping("/test")
    public void test()  {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("1","1");
        BoJunHttpUtils.showtest(jsonObject,1);
    }

    @GetMapping("/test2")
    public void test2()  {
        log.info("正常日志信息打印!");
        accountService.test3();
        THREAD_POOL.execute(()-> log.info("本地线程池执行"));

    }

    @GetMapping("/test1")
    public Double test1()  {
       return 6773388.235 ;
    }

    /**
     *
     * 不生效  代理模式中目标方法执行时，其方法体中调用本类其他方法，会使用this。
     * 而this指的就是目标对象，而非代理对象，所以，这时候还异步个毛啊！！都特么不走代理了
     */
  /*  @Async("asyncExecutor")
    public void test4()  {
        log.info("asyncExecutor自定义线程池异步执行test4");
    }*/
}

